<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<style>
.custom-switch {
    padding-left: 3.25rem;
}
.custom-control {
    position: relative;
    display: block;
    min-height: 1.5rem;
    padding-left: 2.5rem;
}
.custom-control-input {
    position: absolute;
    z-index: -1;
    opacity: 0;
}
.custom-control-label {
    position: relative;
    margin-bottom: 0;
    vertical-align: top;
}
.custom-switch .custom-control-label::before {
    left: -3.25rem;
    width: 1.75rem;
    pointer-events: all;
    border-radius: .5rem;
}
.custom-control-label::before {
    position: absolute;
    top: .25rem;
    left: -2.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    pointer-events: none;
    content: "";
    background-color: #dee2e6;
    border: #adb5bd solid 1px;
    box-shadow: inset 0 0.25rem 0.25rem rgba(0,0,0,.1);
}
.custom-control-label::before, .custom-file-label, .custom-select {
    transition: background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
}
.custom-switch .custom-control-label::after {
    top: calc(.25rem + 2px);
    left: calc(-3.25rem + 2px);
    width: calc(1rem - 4px);
    height: calc(1rem - 4px);
    background-color: #adb5bd;
    border-radius: .5rem;
    transition: background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out;
    transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    transition: transform .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out,-webkit-transform .15s ease-in-out;
}
.custom-control-input:checked~.custom-control-label::before {
    color: #fff;
    border-color: #007bff;
    background: #007bff linear-gradient(180deg,#268fff,#007bff) repeat-x;
    box-shadow: none;
}
.custom-switch .custom-control-input:checked~.custom-control-label::after {
    background-color: #dee2e6;
    -webkit-transform: translateX(.75rem);
    transform: translateX(.75rem);
}
.custom-control-label::after {
    position: absolute;
    top: .25rem;
    left: -2.5rem;
    display: block;
    width: 1rem;
    height: 1rem;
    content: "";
    background: no-repeat 50%/50% 50%;
}

.filter .title-h{font-size:14px;border-bottom:1px solid #dcdcdc;padding-bottom:10px}.filter dl{position:relative;margin-bottom:10px}.filter dl:after{content:"";display:block;clear:both}.filter dl dt{position:absolute;top:0;left:0;font-weight:700}.filter dl dd{padding-left:100px}.filter dl dd a{margin-right:20px;margin-bottom:10px;display:inline-block}.filter dl dd a.on{font-weight:700;color:#477fd2}

.shiprow,.shiplb{cursor:pointer;}
</style>

                    <div class="row">
                        <div class="col-sm-12">
                             <div class="box">
                                <div class="box-header with-border">
                                    <div class=" col-sm-6">
                                    <?php echo form_open(current_url(), array('class' => 'form-inline', 'method'=>'get', 'id' => 'search_goods')); ?>                                    

<div class="form-group" style="margin-right:15px;">

<div class="input-group input-group-sm">
        <?php echo form_input($keyword);?>
       
</div>                                        
</div>
<div class="form-group" >
    <?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-sm btn-primary btn-flat', 'content' => "搜索")); ?>    
</div>


<?php echo form_close();?>
                                        
                                    </div>
                                    <h3 class="box-title pull-right">
                                    
                                    </h3>
                                </div>
                                <div class="box-body">
                                       <?php if($data):?>
                                    <table class="table table-striped table-hover" style="margin-top:20px;">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>账号</th>
                                                <th>支付次数上限</th>
                                                <th>支付金额上限</th>
                                                <th>账号状态</th>
                                                <th>禁用</th>
                                                <th>支付次数</th>
                                                <th>支付金额</th>
                                                <th>备注</th>
                                                <th width="150">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        
<?php foreach ($data as $item):?>
<tr shopid="<?php echo $item["id"]; ?>">
    <td><?php echo $item["id"]; ?></td>
    <td><?php echo $item["account"]; ?></td>
    <td ondblclick="edit(this,'limitcount')"><?php echo $item["limitcount"]; ?></td>
    <td ondblclick="edit(this,'limitamount')"><?php echo $item["limitamount"]; ?></td>
    <td><span class="label label-<?php echo $pstatuslabel[$item["status"]]; ?>"><?php echo $pstatus[$item["status"]];?></span></td>
    <td>
    <div class="custom-control custom-switch" style="margin-left:10px;" cid="<?php echo $item["id"];?>">
        <input type="checkbox" class="custom-control-input manbox" id="mtoogle<?php echo $item["id"];?>" <?php if($item["status"]==2) echo " checked";?>>
        <label class="custom-control-label" for="mtoogle<?php echo $item["id"];?>"></label>
    </div>
    </td>
    <td><?php echo $item["succcount"]; ?></td>
    <td><?php echo $item["succtotal"]; ?></td>
    <td ondblclick="edit(this,'note')"><?php echo $item["note"]?$item["note"]:"双击编辑"; ?></td>
    <td>
    <?php echo anchor('backend/paypal/account/report/'.$item["id"],'<i class="fa fa-bars fa-lg"></i> 报表','class="btn btn-flat btn-xs btn-primary"'); ?>&nbsp&nbsp    
    <?php echo anchor('backend/paypal/account/bind/'.$item["id"],'<i class="fa fa-cloud fa-lg"></i> 绑定','class="btn btn-flat btn-xs btn-info"'); ?>&nbsp&nbsp
    </td>
</tr>
<?php endforeach;?>
                                        </tbody>
                                    </table>

                                    <?php echo $pager;?>

<div class=" pull-right form-inline" style="line-height:30px;margin-top:25px;">
    <?php echo '共'.$total.'条产品，'.$page.'/'.$pages.'页';?> 
</div>

<?php endif;?>

                                    <?php 
                                    if(empty($data)){
                                        echo "<h2 style='text-align:center;padding:50px 0;'>没有查询到数据</h2>";
                                    }
                                    ?>
                                

                                </div>
                            </div>
                         </div>
                    </div>
        


        <?php echo form_open(current_url(), array('class' => 'form-horizontal','onsubmit'=>'return checkform();', 'id' => 'form-create_notice')); ?>
        <div class="row">
             <div class="col-sm-12">
                <div class="box">
       
                 <div class="box-header with-border">
                 <h3 class="box-title">添加账号</h3>
                 </div>

                 <div class="box-body">

                 <div class="row">
                        <div class="col-xs-3">
                            <input type="text" class="form-control" name="account" id="account" placeholder="账号邮箱">
                        </div>

                        <div class="col-xs-3">
                            <input type="text" class="form-control" name="limitcount" id="limitcount" placeholder="支付次数上限">
                        </div>

                        <div class="col-xs-3">
                            <input type="text" class="form-control" name="limitamount" id="limitamount" placeholder="支付金额上限">
                        </div>
                        <div class="col-xs-3">
                            <input type="text" class="form-control" name="note" id="note" placeholder="备注">
                        </div>
                    </div>                                 
                    <div class="row" style="margin-top:10px;">
                        <div class="col-xs-3">
                            <input type="hidden" name="action" value="add">
                            <input type="submit" class="btn btn-flat btn-primary btn-sm" value="添加账号">
                        </div>
                       
                    </div> 

                 </div>
          
              
                </div>
              </div>
            <!-- /.box-body -->
          </div>
        <?php echo form_close();?>
<script>

atedit=0;
    function edit(obj,attrName){
        if (atedit==1)
        return;
        else
        atedit=1;

        var oldHtml = obj.innerHTML;
        var newobj = document.createElement('input');
        newobj.name = attrName;
        newobj.type = "text";
        newobj.setAttribute("class","form-control input-sm");
        if($.trim(oldHtml)!="双击编辑"){
            newobj.value = oldHtml;
        }

        var cid = $(obj).parent().attr("shopid");     
        obj.innerHTML = '';  
        obj.appendChild(newobj);
        newobj.focus(); 

        $(newobj).keydown(function (event) {
            if (event.keyCode == 13) {
                $(this).trigger("blur");
            }
        });

        eurl="/backend/paypal/account/ajaxedit";
        
        $(newobj).blur(function(){
            atedit=0;
            if(this.value==null || this.value==""){
                obj.innerHTML = oldHtml;
                return false;
            }
            obj.innerHTML = this.value?this.value:oldHtml;       
            if(oldHtml != this.value){
                $.ajax({
                    type:"post",
                    url:eurl,
                    dataType:"json",
                    data:{"attrName":attrName,"newHtml":this.value,"cid":cid},
                    error:function(){
                    },
                    success:function(){
                        layer.msg("更新成功");
                    },
                });
            }  

        })
    }


$(document).ready(function() {
   

   

    $("input.manbox").on("click",function(){
        var cid = $(this).parent().attr("cid");     
        if($(this).is(":checked"))
        {
            newval=2;
        }
        else
        {
            newval=1;
        }
        $.ajax({
            type:"post",
            url:"/backend/paypal/account/ajaxedit",
            dataType:"json",
            data:{"attrName":"status","newHtml":newval,"cid":cid},
            error:function(){
            },
            success:function(){
            },
        });
    });


    var checkform = function(){
        checkfild={
        "account":"账号",
        "limitcount":"支付次数上限",
        "limitamount":"支付金额上限",
        };
        for (var index in checkfild) {
            if($("input[name='"+index+"']").val().trim().length==0)
            {
                layer.msg(checkfild[index]+"不能为空");
                return false;
            }
        }
    };



});




</script>
